import React, {PureComponent} from 'react';
import {Provider} from "react-redux";
import store from "./store";
import {Router, Route,Switch} from "react-router-dom";
import "antd/dist/antd.css";
import "./App.css";
import {LocaleProvider} from "antd";
import zh_CN from 'antd/lib/locale-provider/zh_CN';
import 'moment/locale/zh-cn';
import routers from "./Routes";
import history from "./common/route/history";

class App extends PureComponent {


    render() {
        return (
            <Provider store={store}>
                <LocaleProvider locale={zh_CN}>
                    <Router history={history}>
                        {/*这个 用来存储一级路由*/}
                        <div>

                           <Switch>
                               {
                                   routers.map((route, i) => {
                                       if(route.path === "*"){
                                           return  (
                                               <Route
                                                   key={i}
                                                   component={route.component}
                                               />
                                           );
                                       }else{
                                           return  (
                                               <Route
                                                   key={i}
                                                   path={route.path}
                                                   render={props => (
                                                       //主要是为了传递嵌套路由到子组件
                                                       //类似于 <User {...props} routes={route.routes} />
                                                       <route.component {...props} routes={route.routes}/>
                                                   )}
                                               />
                                           );
                                       }

                                   })
                               }
                           </Switch>

                        </div>
                    </Router>
                </LocaleProvider>
            </Provider>
        );
    }
}

export default App;

